package com.example.xungeng2.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.xungeng2.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from user where username = #{username} and password = #{password}")
    User findByUsername_login(@Param("username") String username,
                              @Param("password") String password);

    @Select("select * from user where username = #{username}")
    User findByUsername(@Param("username") String username);

    @Select("select * from user where img = #{url}")
    User findByUrl(@Param("url") String url);

    @Update("update user set img = #{url} where username = #{username}")
    Integer updatePhotoUrl(@Param("username") String username, @Param("url") String url);

    @Select("select realName from user where userId=#{adminId}")
    String selectUserRealName(Integer adminId);

    @Select("select isAssigned from user where userId=#{userId}")
    int selectXGUserStatus(Integer userId);

    @Select("select * from user where userId = #{userId}")
    User findUserById(int parseInt);

    @Update("update user set img = #{url} where userId = #{userId}")
    Integer xgUpdatePhotoUrl(Integer userId, String path);

    @Update("update user set isAssigned=1 where userId=#{u}")
    void changeUserState(int u);
}
